@extends('layout.adminlayout')
@section('css')
<script src="/admin/js/metisMenu.min.js"></script>
<script src="/admin/js/custom.js"></script>
<link href="/admin/css/custom.css" rel="stylesheet">
@endsection
@section('content')
<div class="tables">
	<div class="table-responsive bs-example widget-shadow">
		<h4>设备列表 :</h4>
		<form action="/admin/device/index" method="get">
			{{csrf_field()}}
			<div class="row" style="padding-bottom: 15px;margin-top: 0px;">
				<p class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="width: 70px; height: 32px;padding: 0px;text-align: right;line-height: 32px;">代理商：</p>
				<select name="ag" class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="height: 30px; line-height: 30px; padding: 0px; border: 1px solid #DDD; margin: 0px 10px; width: 10%;">
					<option value="">请选择代理商</option>
					@foreach($agent as $v)
						<option value="{{$v['id']}}"
								@if($get['ag'] == $v['id'])
								selected
								@else
								@if(Cookie::get('agentId') == $v['id'])
								selected
								@endif
								@endif>{!! $v['agent_name'] !!}</option>
					@endforeach
				</select>
				<p class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="width: 70px; height: 32px;padding: 0px;text-align: right;line-height: 32px;">DevEUI：</p>
				<input type="text" name="eui" value="{{$get['eui']}}" class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="height: 30px; line-height: 30px; padding: 0px; border: 1px solid #DDD; margin: 0px 10px; width: 10%;"/>
				<p class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="width: 70px; height: 32px;padding: 0px;text-align: right;line-height: 32px;">区域：</p>
				<input type="text" name="area" value="{{$get['area']}}" class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="height: 30px; line-height: 30px; padding: 0px; border: 1px solid #DDD; margin: 0px 10px; width: 10%;"/>
				<p class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="width: 70px; height: 32px;padding: 0px;text-align: right;line-height: 32px;">建筑：</p>						
				<input type="text" name="building" id="" value="{{$get['building']}}" class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="height: 30px; line-height: 30px; padding: 0px; border: 1px solid #DDD; margin: 0px 10px; width: 10%;"/>
				<p class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="width: 70px; height: 32px;padding: 0px;text-align: right;line-height: 32px;">房间：</p>
				<input type="text" name="room" id="" value="{{$get['room']}}" class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="height: 30px; line-height: 30px; padding: 0px; border: 1px solid #DDD; margin: 0px 10px; width: 10%;"/>
				<input type="submit" value="搜索" class="col-lg-1 col-md-1 col-sm-1 col-xs-1"  style="height: 30px; line-height: 32px; padding: 0px; border: 0; background: #4F52BA;width: 50px; margin: 0px 10px;color:#fff"/>	
			</div>
		</form>
		<table class="table table-bordered" style="text-align: center">
			<thead>
				<!-- <tr>
					<form action="/admin/trace" method="get">
						每页显示:
						<select name="conut">
							<option value="">10</option>
							<option value="">20</option>
							<option value="">50</option>
						</select>条
						<input type="text" name="" />
						<input type="submit" value="搜索" />
					</form> 
				</tr>
 -->			
 				<tr>
					<th style="text-align: center">编号</th>
					<th style="text-align: center">DevEUI</th>
					<th style="text-align: center">类型</th>
					<th style="text-align: center">型号</th>
					<th style="text-align: center">区域</th>
					<th style="text-align: center">建筑</th>
					<th style="text-align: center">房间</th>
					<th style="text-align: center">全体负责人</th>
					<th style="text-align: center">具体位置</th>
					{{--<th style="text-align: center">状态</th>--}}
					<th style="text-align: center">设备绑定时间</th>
					{{--<th style="text-align: center">最新消息时间（心跳间隔）</th>--}}
					@if($get['ag'] == Cookie::get('agentId') || Cookie::get('agentId') == 1)
					<th style="text-align: center">操作</th>
					@endif
				</tr>
			</thead>
			<tbody>
			@if($info != null)
				@foreach($info as $v)
					<tr> 
						<th scope="row" style="text-align: center">{{$v['rd_id']}}</th>
						<td>{{$v['rd_sd_eui']}}</td>
						<td>{{$v['type']}}</td>
						<td>{{$v['t_model']}}</td>
						<td><a href="/admin/area/index?ag=@if($get['ag']){{$get['ag']}}@else{{$v['rd_agent_id']}}@endif&area={{$v['a_name']}}">{{$v['a_name']}}</a></td>
						<td><a href="/admin/building/index?ag=@if($get['ag']){{$get['ag']}}@else{{$v['rd_agent_id']}}@endif&area={{$v['a_name']}}&building={{$v['b_name']}}">{{$v['b_name']}}</a></td>
						<td><a href="/admin/room/index?ag=@if($get['ag']){{$get['ag']}}@else{{$v['rd_agent_id']}}@endif&area={{$v['a_name']}}&building={{$v['b_name']}}&room={{$v['r_name']}}">{{$v['r_name']}}</a></td>
						<td>
							@if($v['a_user_str']!= '')
								区域 : {{$v['a_user_str']}}
							@endif
							@if($v['b_user_str'] != '')
								建筑 : {{$v['b_user_str']}}
							@endif
							@if($v['r_user_str'] != '')
								房间 : {{$v['r_user_str']}}
							@endif
						</td>
						<td>{{$v['rd_location']}}</td>
						<td>{{$v['rd_add_time']}}</td>
						@if($get['ag'] == Cookie::get('agentId') || Cookie::get('agentId') == 1)
						<td><a href="/admin/device/edit?rd_id={{$v['rd_id']}}">编辑</a>&nbsp;|&nbsp;<a href="javascript:void (0)" onclick=del({{$v['rd_id']}})>删除</a></td>
						@endif
					</tr>
					@endforeach
				@endif
			</tbody> 
		</table>
		@if(!null == $data)
			<div style="float:right;">
				{!! $data->appends($request)->render() !!}
			</div>
		@endif
	</div>
</div>
<script>
	function del(id) {
        $.ajax({
            type:'post',
            url:'/admin/device/del',
            async:false,
            data:{
                "_token": $("input[name=_token]").val(),
                'id':id
            },
            dataType:'json',
            success:function (data) {
                if(data.status == '1'){
                    location.href = '/admin/device/index';
                }
                return false;
            }
        })
    }
</script>
@endsection